package org.phantom.securityframework.api.factory;

import org.apache.shiro.config.Ini;
import org.apache.shiro.config.IniFactorySupport;
import org.apache.shiro.util.ClassUtils;
/**
 * 获取当前环境配置的ManagerFactory实例 
 * @author david
 *
 */
@SuppressWarnings("rawtypes")
public class ShiroRealmFactory extends IniFactorySupport{

	private static ShiroRealmFactory me = new ShiroRealmFactory();
	private ShiroRealmFactory(){
		
	}
	/**
	 * 获取ManagerFactory实例
	 * @param ini
	 * @return
	 */
	public static ManagerFactory getInstance(Ini ini){
		return me.createInstance(ini);
	}
	
	@Override
	protected ManagerFactory createInstance(Ini ini) {
		if(ini==null)return null;
		try {
			String factory = ini.getSectionProperty("realms", "factory");
			if(factory!=null){
				return (ManagerFactory) Class.forName(factory).newInstance();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
		}
		return  null;
	}

	@Override
	protected ManagerFactory createDefaultInstance() {
		return new SpringManagerFactory();
	}

}
